package com.twu.biblioteca;

import java.util.ArrayList;

public class User {

    private static int availableLibraryNumber = 1111;
    private static ArrayList<User> userList = new ArrayList<User>();

    private String UserName;
    private String password;
    private int currentUserLibraryNumber;
    private String email;
    private String phoneNumber;


    public User(String username,String password)
    {
        this.UserName=username;
        this.password=password;
        this.currentUserLibraryNumber = availableLibraryNumber++;

        addUserToList(this);
    }

    public User(String username,String password, String email, String phone)
    {
        this.UserName=username;
        this.password=password;
        this.email = email;
        this.phoneNumber = phone;
        this.currentUserLibraryNumber = availableLibraryNumber++;

        addUserToList(this);
    }

    public static User login(String username, String password)
    {
        for(User user:userList)
        {
            if(user.getUserName().equalsIgnoreCase(username) && user.getPassword().equals(password))
                return user;
        }
        return null;
    }

    public void addUserToList(User user)
    {
        if(!userList.contains(user))
        {
            userList.add(user);
        }
    }

    public String getUserName() {
        return UserName;
    }

    public String getPassword() {
        return password;
    }

    public String getCurrentUserLibraryNumber() {
        return Integer.toString(currentUserLibraryNumber).subSequence(0,3) + " - " + Integer.toString(currentUserLibraryNumber);
    }

    public String getEmail() {
        return email;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }
}
